package org.example.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.example.mapper.UserMapper;
import org.example.pojo.User;
import org.example.service.UserService;
import org.example.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<User> userLogin(User user) {
        return userMapper.userLogin(user);
    }

    @Override
    public Result userRegister(User user) {
        Integer u = userMapper.usernameUsed(user);
        Integer e = userMapper.emailUsed(user);
        if (u != 0) {
            return Result.error("该用户名已被注册");
        }
        if (e != 0) {
            return Result.error("该邮箱已被注册");
        }
        userMapper.userRegister(user);
        return Result.success();
    }
}
